home *** CD-ROM | disk | FTP | other *** search
/ Gigantic Games 2 / Gigantic Games 2.iso / pc / _b_ / boomerang / boomerang.c < prev    next >
C/C++ Source or Header  |  1994-12-23  |  23KB  |  715 lines

  1. /* 
  2.    Boomerang
  3.    by Kevin Dixon
  4.    Amiga version by Troy Tucker using Lattice C (V5.02)
  5.    Copyright © 1990 COMPUTE! Publications, Inc.
  6.    All Rights Reserved
  7. */ 
  8.  
  9. #define STILL  0
  10. #define UP     1
  11. #define DOWN   2
  12. #define LEFT   3
  13. #define RIGHT  4
  14. #define ESC    0x045
  15. #define RETURN 0x044
  16. #define SPACE  0x040
  17.  
  18. #define NUMSAMPLES 3
  19. #define JIF0 8
  20. #define PER0 400
  21. #define VOL0 48
  22. #define JIF1 1
  23. #define PER1 250   
  24. #define VOL1 64
  25. #define JIF2 8
  26. #define PER2 500
  27. #define VOL2 64
  28.  
  29. void openthelibs(),openthefiles(),initthebmaps(),openthescreen();
  30. void readthepic(),initialize(),gameloop(),setbitmap(),opensounds(),pause();
  31. void checkmen(),checkboomerangs(),placeobjects(),changemen(),moveboomerangs();
  32. void dotitle(),flipem(),readthesticks(),cleantheamiga(),getnewboard();
  33.  
  34. #include <stdio.h>
  35. #include <intuition/intuition.h>
  36. #include <exec/memory.h>
  37. #include <hardware/blit.h>
  38. #include <graphics/copper.h>
  39. #include <graphics/view.h>
  40. #include "boomsound.c"
  41.  
  42. short frame=0,direction[2],olddirection[2],px[2],py[2],ox[2],oy[2];
  43. short shapex[2],shapey[2],animate[2],startword,speed=2,bspeed=4,lives[2];
  44. short bx[2],by[2],obx[2],oby[2],bshapex[2],bshapey[2],bflag[2],bstate[2];
  45. short rpx1[2],rpy1[2],rpx2[2],rpy2[2],rpx3[2],rpy3[2],bdirection[2],obstate[2];
  46. short brpx1[2],brpy1[2],brpx2[2],brpy2[2],safethrow[2],deadshapex,deadshapey;
  47. short bulbx[2],bulby[2],bulbshapex[2],bulbshapey[2],dead[2],next=0,reset=0;
  48. char *cia,*filename,numplanes=4;
  49. short *joy[2];
  50. UWORD *copperlist;
  51.  
  52. FILE *IFFfile;
  53. struct Screen *scr;
  54. struct Window *wdw;
  55. struct ViewPort *vp;
  56. struct View *v;
  57. struct RastPort *rp;
  58. struct IntuitionBase *IntuitionBase;
  59. struct IntuiMessage *message;
  60. struct GfxBase *GfxBase;
  61. struct BitMap *Bmap[5] = {NULL,NULL,NULL,NULL,NULL};
  62. struct TextAttr StdFont =
  63. { "topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT };
  64. struct NewScreen my_screen =
  65. { 0,0,320,200,4,0,1,NULL,CUSTOMSCREEN|CUSTOMBITMAP,&StdFont,NULL,NULL,NULL};
  66. struct NewWindow my_window =
  67. { 0,0,320,200,-1,-1,RAWKEY,RMBTRAP|ACTIVATE|BORDERLESS|BACKDROP|NOCAREREFRESH,
  68.   NULL,NULL,NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN };
  69.  
  70. UWORD blackmap[16]={ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
  71. UWORD chip Blank_Data[6] = {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
  72. UWORD colormap[16]=
  73. { 0x0002,0x0223,0x0c00,0x0f60,0x0070,0x0040,0x000f,0x0000,
  74.   0x0f8b,0x080b,0x0407,0x0830,0x0fe0,0x0dd9,0x0774,0x0332
  75. };
  76.  
  77. void main()
  78. {
  79.  openthelibs();
  80.  printf ("\n\n              Boomerang\n");
  81.  printf ("            by Kevin Dixon\n");
  82.  printf ("     Amiga version by Troy Tucker\n");
  83.  printf (" Copyright © 1990 COMPUTE! Pub., Inc.\n");
  84.  printf ("         All Rights Reserved\n\n");
  85.  waveform[0]=LoadSample("samples/footsteps.snd",&wavelength[0]);
  86.  waveform[1]=LoadSample("samples/spin.snd",&wavelength[1]);
  87.  waveform[2]=LoadSample("samples/boom.snd",&wavelength[2]);
  88.  initthebmaps();
  89.  openthescreen();
  90.  openthefiles();
  91.  Forbid();
  92.  initialize();
  93.  dotitle();
  94.  gameloop();
  95. }
  96.  
  97. void openthelibs()                     /* open the libraries */
  98.   IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0);
  99.   if (IntuitionBase == NULL) exit(FALSE);
  100.   GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0);
  101.   if (GfxBase == NULL)
  102.     { CloseLibrary("intuition.library");
  103.       exit(FALSE);
  104.     }
  105. }
  106.  
  107. void initthebmaps()                    /* allocate bmaps and clear them */
  108. {
  109.  register short i,j;
  110.  
  111.  for (j=0; j<5; j++)
  112.   {
  113.    if ((Bmap[j]=(struct BitMap *)AllocMem(sizeof(struct BitMap),MEMF_CHIP))==0)
  114.       cleantheamiga();
  115.    InitBitMap (Bmap[j],4,320,200);
  116.    for (i=0; i<4; i++)
  117.     { if ((Bmap[j]->Planes[i] = (PLANEPTR)AllocRaster(320,200)) == 0)
  118.          cleantheamiga();
  119.       BltClear(Bmap[j]->Planes[i],(320 / 8)*200,1);
  120.     }
  121.   }
  122.  my_screen.CustomBitMap = Bmap[0];
  123.  
  124. void openthescreen()               /* open window,screen,kill pointer,etc. */
  125. {
  126.  if ((scr=(struct Screen *)OpenScreen(&my_screen))==NULL)
  127.    { printf("Can't open the screen \n");
  128.      cleantheamiga();
  129.    }
  130.  my_window.Screen = scr;
  131.  if ((wdw=(struct Window *)OpenWindow(&my_window))==NULL)
  132.    { printf("Can't open the window \n");
  133.      cleantheamiga();
  134.    }
  135.  SetPointer(wdw,&Blank_Data[0],1,1,0,0);
  136.  vp=(struct ViewPort *)&scr->ViewPort;;
  137.  v=(struct View *)ViewAddress();
  138.  rp=&scr->RastPort;
  139.  copperlist = (UWORD *)v->LOFCprList->start;
  140.  startword=0;
  141.  while (*(copperlist+startword) != (UWORD)0x00e0) startword += 2;
  142. }
  143.  
  144. void openthefiles()                    /* open pics for reading */
  145. {
  146.  LoadRGB4(vp,&blackmap,16);
  147.  scr->BitMap = *Bmap[3];
  148.  filename="boomer1.pic";
  149.  readthepic();
  150.  scr->BitMap = *Bmap[4];
  151.  filename="boomer2.pic";
  152.  readthepic();
  153.  BltBitMap(Bmap[4],0,0,Bmap[2],0,0,320,200,0xC0,0xff,NULL);
  154. }
  155.  
  156. void readthepic()                      /* DPaintIII (320x200) pic reader  */
  157. {
  158.  char *newbyte[8], context_header[4], code, counter, goodbyte;
  159.  short Height, Plane, bytes_read, bytes_per_row=320>>3;
  160.  
  161.  IFFfile=fopen(filename,"r");                          
  162.  if (IFFfile==NULL)
  163.    { printf("Can't find the pictures! \n");
  164.      exit(FALSE);
  165.    }
  166.  for (counter=0; counter<80; counter++) /* skip to BODY */
  167.  fread(context_header,4,1,IFFfile);
  168.  fread(context_header,2,1,IFFfile);
  169.  fread(context_header,4,1,IFFfile);  
  170.  if (strcmp(context_header,"BODY")!=0)
  171.    { printf("Something's wrong with the pictures! \n");
  172.      cleantheamiga();
  173.    }
  174.  fread(context_header,4,1,IFFfile);
  175.  for (Plane=0; Plane<numplanes; Plane++)          /* read in the body */
  176.     newbyte[Plane]=(char *)(scr->RastPort.BitMap->Planes[Plane]); 
  177.  for (Height=0; Height<200; Height++)
  178.   { for (Plane=0; Plane<numplanes; Plane++)
  179.     { bytes_read=0;
  180.       do
  181.       { fread(&code,1,1,IFFfile);
  182.         if (code>=0) 
  183.         { code++;
  184.           fread(newbyte[Plane],(long)code,1,IFFfile);
  185.           newbyte[Plane] += code;
  186.           bytes_read += code;
  187.         }
  188.         else if (code != -127) 
  189.          { code = -code;
  190.            code++;
  191.            fread(&goodbyte,1,1,IFFfile);
  192.            for (counter=0; counter<code; counter++)
  193.            { *newbyte[Plane]=goodbyte;
  194.               newbyte[Plane]++;
  195.            }
  196.            bytes_read += code;
  197.          }
  198.       }
  199.       while ((bytes_read<bytes_per_row) && feof(IFFfile)==0);
  200.     }
  201.   }
  202.  fclose(IFFfile);
  203. }
  204.  
  205. void initialize()                      /* refreshes vars between rounds */
  206. {
  207.  register short i,x;
  208.  
  209.  if ((lives[0]==6)&&(lives[1]==6))     /* light up the lifebulbs */
  210.    {
  211.     x=215;
  212.     for (i=0;i<5;i++)
  213.        {
  214.         BltBitMap(Bmap[3],70,80,
  215.         Bmap[2],x,190,5,5,0xC0,0xff,NULL);
  216.         x=x+14;
  217.        }
  218.      x=46;
  219.      for (i=0;i<5;i++)
  220.        {
  221.         BltBitMap(Bmap[3],70,90,
  222.         Bmap[2],x,190,5,5,0xC0,0xff,NULL);
  223.         x=x+14;
  224.        }
  225.    }
  226.  px[0]=292,px[1]=14,py[0]=12,py[1]=164;  
  227.  ox[0]=292,ox[1]=14,oy[0]=12,oy[1]=164;  
  228.  rpx1[0]=rpx2[0]=rpx3[0]=rpy1[0]=rpy2[0]=rpy3[0]=px[0];
  229.  rpx1[1]=rpx2[1]=rpx3[1]=rpy1[1]=rpy2[1]=rpy3[1]=px[0];
  230.  bshapex[0]=15,bshapey[0]=79,bshapex[1]=35,bshapey[1]=89;
  231.  shapex[0]=15,shapey[0]=28,shapex[1]=15,shapey[1]=44;
  232.  deadshapex=0,dead[0]=0,dead[1]=0;
  233.  joy[1] = (short *)(0xdff00a);                     /* Joystick 1 (port 1) */
  234.  joy[0] = (short *)(0xdff00c);                     /* Joystick 0 (mouse)  */
  235.  cia = (char *)(0xbfe001);
  236.  animate[0]=0; animate[1]=0;
  237.  bflag[0]=bflag[1]=bstate[0]=bstate[1]=0;
  238.  safethrow[0]=safethrow[1]=0;
  239.  bdirection[0]=LEFT,bdirection[1]=RIGHT;
  240.  direction[0]=LEFT,direction[1]=RIGHT;
  241.  olddirection[0]=LEFT,olddirection[1]=RIGHT;
  242.  /* make the screen copies */
  243.  BltBitMap(Bmap[2],0,0,Bmap[0],0,0,320,200,0xC0,0xff,NULL);
  244.  BltBitMap(Bmap[2],0,0,Bmap[1],0,0,320,200,0xC0,0xff,NULL);
  245.  /* blit the men */
  246.  BltBitMap(Bmap[3],shapex[0]+112,shapey[0],Bmap[0],px[0],py[0],13,15,0x20,0xff,NULL);
  247.  BltBitMap(Bmap[3],shapex[0],shapey[0],Bmap[0],px[0],py[0],13,15,0xE0,0xff,NULL);
  248.  BltBitMap(Bmap[3],shapex[1]+112,shapey[1],Bmap[0],px[1],py[1],13,15,0x20,0xff,NULL);
  249.  BltBitMap(Bmap[3],shapex[1],shapey[1],Bmap[0],px[1],py[1],13,15,0xE0,0xff,NULL);
  250.  frame=0;
  251.  scr->BitMap = *Bmap[0];
  252.  setbitmap();
  253.  frame=1;
  254.  pause(255);
  255.  LoadRGB4(vp,&colormap,16);
  256. }
  257.  
  258. void dotitle()                         /* place select box then get input */
  259. {
  260.  register short i;
  261.  ULONG class;
  262.  USHORT code = 0;
  263.  BltBitMap(Bmap[3],14,127,Bmap[1-frame],98,78,124,38,0xC0,0xff,NULL);
  264.  lives[0]=lives[1]=6;
  265.  bulbx[0]=215,bulby[0]=190,bulbx[1]=102,bulby[1]=190;
  266.  bulbshapex[0]=59,bulbshapey[0]=80,bulbshapex[1]=59,bulbshapey[1]=90;
  267.  deadshapex=0,deadshapey=99,dead[0]=0,dead[1]=0;
  268.  *dmaconw=0x000F; for (i=0;i<4;i++) inuse[i]=0;
  269.  Permit();
  270.  
  271.  while (code != RETURN)
  272.     { Wait(1<<wdw->UserPort->mp_SigBit);
  273.       while (message = (struct IntuiMessage *)GetMsg(wdw->UserPort))
  274.         {
  275.          code = message->Code;
  276.          class = message->Class;
  277.          ReplyMsg(message);
  278.          if ((class==RAWKEY)&&(code==ESC)) cleantheamiga();
  279.          if ((class==RAWKEY)&&(code==SPACE))
  280.            { BltBitMap(Bmap[4],0,0,Bmap[2],0,0,320,200,0xC0,0xff,NULL);
  281.              getnewboard();
  282.              initialize();
  283.              BltBitMap(Bmap[3],14,127,Bmap[1-frame],
  284.              98,78,124,38,0xC0,0xff,NULL);
  285.            }
  286.         }
  287.     }
  288.  Forbid();
  289.  BltBitMap(Bmap[2],98,78,Bmap[1-frame],98,78,124,38,0xC0,0xff,NULL);
  290. }
  291.  
  292. void getnewboard()                     /* random board generator */
  293. {
  294.  register short i,j,wx,wy,wd,wl;
  295.  ULONG Seconds,Micros,seed;
  296.  CurrentTime(&Seconds, &Micros);
  297.  seed=Seconds + Micros;
  298.  srand(seed);
  299.  
  300.  for (i=0;i<20;i++)
  301.     {
  302.      wx=((rand() % 28)*10)+25;
  303.      wy=((rand() % 16)*10)+25;
  304.      wd=(rand() % 10);
  305.      if (wd>5) wd=1;
  306.      else wd=0;
  307.      wl=(rand() % 7)+2;
  308.      for (j=0; j<wl; j++)
  309.       {
  310.        if ((wx>280)||(wy>160)) break;
  311.        BltBitMap(Bmap[3],26,180,Bmap[2],wx,wy,11,11,0x20,0xff,NULL);
  312.        BltBitMap(Bmap[3],14,180,Bmap[2],wx,wy,11,11,0xE0,0xff,NULL);
  313.        if (wd==0) wx=wx+10;
  314.        else wy=wy+10;
  315.       } 
  316.     }
  317. }
  318.  
  319. void setbitmap()                       /* Tell copper to display Bmap */
  320. {
  321.  *(copperlist+startword+1)  = ((ULONG)(Bmap[frame]->Planes[0]) / 65536);
  322.  *(copperlist+startword+3)  = ((ULONG)(Bmap[frame]->Planes[0]) % 65536);
  323.  *(copperlist+startword+5)  = ((ULONG)(Bmap[frame]->Planes[1]) / 65536);
  324.  *(copperlist+startword+7)  = ((ULONG)(Bmap[frame]->Planes[1]) % 65536);
  325.  *(copperlist+startword+9)  = ((ULONG)(Bmap[frame]->Planes[2]) / 65536);
  326.  *(copperlist+startword+11) = ((ULONG)(Bmap[frame]->Planes[2]) % 65536);
  327.  *(copperlist+startword+13) = ((ULONG)(Bmap[frame]->Planes[3]) / 65536);
  328.  *(copperlist+startword+15) = ((ULONG)(Bmap[frame]->Planes[3]) % 65536);
  329. }
  330.  
  331. void gameloop()                        /* main game loop */
  332. {
  333.  for (;;)
  334.  {
  335.   UpdateSounds();
  336.   if ((dead[0]==0) && (dead[1]==0))
  337.     {
  338.      readthesticks();
  339.      checkmen();
  340.      changemen();
  341.      moveboomerangs();
  342.      checkboomerangs();
  343.     }
  344.   placeobjects();
  345.   if ((dead[0])||(dead[1])) pause(100);
  346.   if (reset==1)
  347.     { 
  348.       reset=0;
  349.       pause(255);
  350.       if ((lives[0]==0)||(lives[1]==0)) dotitle();
  351.       initialize();
  352.     }
  353.  }
  354. }
  355.  
  356. void readthesticks()                   /* update x & y for men */
  357. {
  358.  register short port,i;
  359.  for (i=0; i<2; i++)
  360.   {
  361.     port=2-i;
  362.     direction[i]=STILL;
  363.  
  364.     if ((!(*cia & 64 * port))&&(bflag[i]==0)&&(safethrow[i]==0))
  365.       { bflag[i]=1;
  366.         bstate[i]=1;
  367.         obstate[i]=0;
  368.       }
  369.  
  370.     if (*joy[i] & 512)               /* stick left   */
  371.       { direction[i]=LEFT;
  372.         bdirection[i]=LEFT;
  373.         px[i]=px[i]-speed;
  374.         rpx1[i]=px[i];   rpy1[i]=py[i]+1;
  375.         rpx2[i]=rpx1[i]; rpy2[i]=py[i]+7;
  376.         rpx3[i]=rpx1[i]; rpy3[i]=py[i]+13;
  377.         continue;
  378.       }
  379.     if (*joy[i] & 2)                 /* stick right  */
  380.       { direction[i]=RIGHT;
  381.         bdirection[i]=RIGHT;
  382.         px[i]=px[i]+speed;
  383.         rpx1[i]=px[i]+11; rpy1[i]=py[i]+1;
  384.         rpx2[i]=rpx1[i];  rpy2[i]=py[i]+7;
  385.         rpx3[i]=rpx1[i];  rpy3[i]=py[i]+13;
  386.         continue;
  387.       }
  388.     if ((*joy[i]>>1^*joy[i])&256)    /*  stick up    */
  389.       { direction[i]=UP;
  390.         bdirection[i]=UP;
  391.         py[i]=py[i]-speed;
  392.         rpx1[i]=px[i]+3;  rpy1[i]=py[i];
  393.         rpx2[i]=px[i]+6;  rpy2[i]=rpy1[i];
  394.         rpx3[i]=px[i]+9;  rpy3[i]=rpy1[i];
  395.         continue;
  396.       }
  397.     if ((*joy[i]>>1^*joy[i])&1)      /*  stick down  */
  398.       { direction[i]=DOWN;
  399.         bdirection[i]=DOWN;
  400.         py[i]=py[i]+speed;
  401.         rpx1[i]=px[i]+3;  rpy1[i]=py[i]+13;
  402.         rpx2[i]=px[i]+6;  rpy2[i]=rpy1[i];
  403.         rpx3[i]=px[i]+9;  rpy3[i]=rpy1[i];
  404.         continue;
  405.       }
  406.   }
  407. }
  408.  
  409. void checkmen()
  410. {
  411.  register short color1,color2,color3,i;
  412.  for (i=0;i<2;i++)
  413.     {
  414.      safethrow[i]=0;
  415.      if (px[i]<2)   px[i]=303;         /* man run into wall? */
  416.      else  if (px[i]>303) px[i]=2;
  417.      if (py[i]<2)   py[i]=174;
  418.      else  if (py[i]>174) py[i]=2;
  419.      color1 = ReadPixel(rp,rpx1[i],rpy1[i]);
  420.      color2 = ReadPixel(rp,rpx2[i],rpy2[i]);
  421.      color3 = ReadPixel(rp,rpx3[i],rpy3[i]);
  422.      if ((color1>1)||(color2>1)||(color3>1))
  423.        {
  424.          px[i]=ox[i];
  425.          py[i]=oy[i];
  426.          safethrow[i]=1;
  427.        }
  428.     }
  429. }  
  430.  
  431. void changemen()                       /* player shape changer */
  432. {
  433.  register short i;
  434.  for (i=0; i<2; i++)
  435.    {
  436.     if ((animate[i]==4)||(olddirection[i] != direction[i]))
  437.       {
  438.         switch(direction[i])
  439.           {
  440.             case (LEFT):  if (olddirection[i]==LEFT) shapex[i]=shapex[i]+14;
  441.                           else
  442.                             { shapex[i]=15;
  443.                               olddirection[i]=LEFT;
  444.                             }
  445.                           if (i==0) shapey[i]=28;
  446.                           else shapey[i]=60;
  447.                           if (shapex[i] > 57) shapex[i]=15;
  448.                           break;
  449.  
  450.             case (RIGHT): if (olddirection[i]==RIGHT) shapex[i]=shapex[i]+14;
  451.                           else
  452.                             { shapex[i]=15;
  453.                               olddirection[i]=RIGHT;
  454.                             }
  455.                           if (i==0) shapey[i]=12;
  456.                           else shapey[i]=44;
  457.                           if (shapex[i] > 57) shapex[i]=15;
  458.                           break;
  459.  
  460.             case (UP):    if (olddirection[i]==UP) shapex[i]=shapex[i]+14;
  461.                           else
  462.                             {  shapex[i]=85;
  463.                                olddirection[i]=UP;
  464.                             }
  465.                           if (i==0) shapey[i]=28;
  466.                           else shapey[i]=60;
  467.                           if (shapex[i] > 99) shapex[i]=85;
  468.                           break;
  469.  
  470.             case (DOWN):  if (olddirection[i]==DOWN) shapex[i]=shapex[i]+14;
  471.                           else
  472.                             { shapex[i]=85;
  473.                               olddirection[i]=DOWN;
  474.                             }
  475.                           if (i==0) shapey[i]=12;
  476.                           else shapey[i]=44;
  477.                           if (shapex[i] > 99) shapex[i]=85;
  478.                           break;
  479.           }
  480.       }
  481.     if (direction[i] != STILL) 
  482.       StartSound(waveform[0],wavelength[0],JIF0,PER0,VOL0,i+2);
  483.     if (animate[i]==4) animate[i]=0;
  484.     animate[i]++;
  485.    }
  486. }
  487.  
  488. void moveboomerangs()                  /* update x & y for boomerangs */
  489. {
  490.  register short i;
  491.  for (i=0;i<2;i++)
  492.     {
  493.      if ((bflag[i])&&(bstate[i]))
  494.       {
  495.        switch(bdirection[i])
  496.         {
  497.          case (LEFT):  if (obstate[i]==0)
  498.                          { bx[i]=px[i]-6; by[i]=py[i]+3; } 
  499.                        bx[i]=bx[i]-bspeed;
  500.                        brpx1[i]=bx[i]-1; brpy1[i]=by[i]+2;
  501.                        brpx2[i]=bx[i]-1; brpy2[i]=by[i]+6;
  502.                        break;
  503.  
  504.          case (RIGHT): if (obstate[i]==0)
  505.                          { bx[i]=px[i]+8; by[i]=py[i]+3; }
  506.                        bx[i]=bx[i]+bspeed;
  507.                        brpx1[i]=bx[i]+8; brpy1[i]=by[i]+2;
  508.                        brpx2[i]=bx[i]+8; brpy2[i]=by[i]+6;
  509.                        break;
  510.  
  511.          case (UP):    if (obstate[i]==0)
  512.                          { bx[i]=px[i]+3; by[i]=py[i]-5; }
  513.                        by[i]=by[i]-bspeed;
  514.                        brpx1[i]=bx[i]+2; brpy1[i]=by[i];
  515.                        brpx2[i]=bx[i]+6; brpy2[i]=by[i];
  516.                        break;
  517.  
  518.          case (DOWN):  if (obstate[i]==0)
  519.                          { bx[i]=px[i]+3; by[i]=py[i]+11; }
  520.                        by[i]=by[i]+bspeed;
  521.                        brpx1[i]=bx[i]+2; brpy1[i]=by[i]+7;
  522.                        brpx2[i]=bx[i]+6; brpy2[i]=by[i]+7;
  523.                        break;
  524.         }
  525.        if ((brpy1[i]<1)||(brpy2[i]<1))     brpy1[i]=brpy2[i]=179;
  526.        else if ((brpy1[i]>179)||(brpy2[i]>179)) brpy1[i]=brpy2[i]=1;
  527.        if ((brpx1[i]<1)||(brpx2[i]<1))     brpx1[i]=brpx2[i]=310;
  528.        else if ((brpx1[i]>310)||(brpx2[i]>310)) brpx1[i]=brpx2[i]=1;
  529.        if (animate[i]==4)
  530.          {  bshapex[i]=bshapex[i]+10;
  531.             if (bshapex[i] > 45) bshapex[i] = 15;
  532.          }
  533.       }
  534.     }
  535. }
  536.  
  537. void checkboomerangs()                 /* check boomerangs for collisions */
  538. {
  539.  register short i,color1,color2,color3,ch;
  540.  for (i=0;i<2;i++)
  541.   {                                    /* is boomerang out there? */
  542.    if (bflag[i])                     
  543.     {                                  /* did it hit the enemy?   */
  544.      if ((((bx[i]   > px[1-i]) && (bx[i]   < px[1-i]+12))  && /* hit enemy? */
  545.           ((by[i]   > py[1-i]) && (by[i]   < py[1-i]+12))) ||
  546.          (((bx[i]+8 > px[1-i]) && (bx[i]+8 < px[1-i]+12))  &&
  547.           ((by[i]+8 > py[1-i]) && (by[i]+8 < py[1-i]+12))))
  548.        {                              
  549.         *dmaconw=0x000F; for (ch=0;ch<4;ch++) inuse[ch]=0;
  550.         StartSound(waveform[2],wavelength[2],JIF2,PER2,VOL2,0);
  551.         lives[1-i]--;
  552.         dead[1-i]=1;
  553.         next=20;
  554.         if (lives[1-i] > 0) BltBitMap(Bmap[3],bulbshapex[1-i],bulbshapey[1-i],
  555.                             Bmap[2],bulbx[1-i],190,5,5,0xC0,0xff,NULL);
  556.         if (i==1) bulbx[0]=bulbx[0]+14;
  557.           else bulbx[1]=bulbx[1]-14;
  558.        }
  559.                                        /* pick up boomerang if out there */
  560.  
  561.      if (((rpx2[i]>=bx[i])&&(rpx2[i]<=bx[i]+8)) &&             
  562.             ((rpy2[i]>=by[i])&&(rpy2[i]<=by[i]+8)))
  563.           {
  564.            bflag[i]=0;
  565.            BltBitMap(Bmap[2],bx[i],by[i],Bmap[frame],
  566.            bx[i],by[i],9,9,0xC0,0xff,NULL);
  567.            BltBitMap(Bmap[2],obx[i],oby[i],Bmap[1-frame],
  568.            obx[i],oby[i],9,9,0xC0,0xff,NULL);
  569.           }
  570.      
  571.      if (bstate[i]==1)                 /* boomerang flying?   */
  572.        {
  573.         if (bx[i]<1) bx[i]=310;    
  574.         else if (bx[i]>310) bx[i]=1;
  575.         if (by[i]<1) by[i]=179;
  576.         else if (by[i]>179) by[i]=1;        /* boomerang hit a wall? */
  577.         if (obstate[i]==0)
  578.           { obx[i]=bx[i];
  579.             oby[i]=by[i];
  580.           }
  581.         color1 = ReadPixel(rp,brpx1[i],brpy1[i]);
  582.         color2 = ReadPixel(rp,brpx2[i],brpy2[i]);
  583.         color3 = ReadPixel(rp,bx[i]+4,by[i]+4); 
  584.         if ((color1>1)||(color2>1)||(color3>1)) 
  585.           { bstate[i]=0;
  586.             if (obstate[i]==0)
  587.               { bflag[i]=0;
  588.                 BltBitMap(Bmap[2],bx[i],by[i],Bmap[frame],
  589.                 bx[i],by[i],9,9,0xC0,0xff,NULL);
  590.                 BltBitMap(Bmap[2],obx[i],oby[i],Bmap[1-frame],
  591.                 obx[i],oby[i],9,9,0xC0,0xff,NULL);
  592.                 continue;
  593.               }
  594.              else
  595.               {
  596.                bx[i]=obx[i];
  597.                by[i]=oby[i];
  598.               }
  599.           }
  600.                                        /* boomerang hit thrower? */
  601.  
  602.         if ((((brpx1[i] > px[i]+3)&&(brpx1[i] < px[i]+8))  &&
  603.              ((brpy1[i] > py[i]+3)&&(brpy1[i] < py[i]+8))) ||
  604.             (((brpx2[i] > px[i]+3)&&(brpx2[i] < px[i]+8))  &&
  605.              ((brpy2[i] > py[i]+3)&&(brpy2[i] < py[i]+8))))
  606.           {      
  607.            bflag[i]=bstate[i]=0;
  608.            BltBitMap(Bmap[2],bx[i],by[i],Bmap[frame],
  609.            bx[i],by[i],9,9,0xC0,0xff,NULL);
  610.            BltBitMap(Bmap[2],obx[i],oby[i],Bmap[1-frame],
  611.            obx[i],oby[i],9,9,0xC0,0xff,NULL);
  612.           }
  613.         if ((animate[i]==4)&&(bstate[i]==1)) 
  614.           StartSound(waveform[1],wavelength[1],JIF1,PER1,VOL1,i);
  615.        }
  616.     }
  617.   } 
  618. }
  619.  
  620. void placeobjects()        /* Bust holes in background & place objects */
  621. {
  622.  register short i;
  623.  for (i=0;i<2;i++)
  624.   {
  625.    if (dead[i]==0)                     /* if man is safe */
  626.     {
  627.      BltBitMap(Bmap[3],shapex[i]+112,shapey[i],Bmap[frame],
  628.      px[i],py[i],13,15,0x20,0xff,NULL);
  629.      BltBitMap(Bmap[3],shapex[i],shapey[i],Bmap[frame],
  630.      px[i],py[i],13,15,0xE0,0xff,NULL);
  631.     }
  632.    else                                /* else kill him  */
  633.     {
  634.      if (deadshapex==0) deadshapex=15;
  635.      else deadshapex=deadshapex+next;
  636.      if (deadshapex>75)
  637.        { deadshapex=55;
  638.          next=-20;
  639.        }
  640.      if (deadshapex<15) reset=1;
  641.      else
  642.        {
  643.         BltBitMap(Bmap[3],deadshapex+112,deadshapey,Bmap[frame],
  644.         px[i]-2,py[i]-2,19,17,0x20,0xff,NULL);
  645.         BltBitMap(Bmap[3],deadshapex,deadshapey,Bmap[frame],
  646.         px[i]-2,py[i]-2,19,17,0xE0,0xff,NULL);
  647.        }
  648.     }
  649.    if (bflag[i])                       /* blit boomerang */
  650.      {
  651.       BltBitMap(Bmap[3],bshapex[i]+112,bshapey[i],Bmap[frame],
  652.       bx[i],by[i],9,9,0x20,0xff,NULL);
  653.       BltBitMap(Bmap[3],bshapex[i],bshapey[i],Bmap[frame],
  654.       bx[i],by[i],9,9,0xE0,0xff,NULL);
  655.      }
  656.   }
  657.  
  658.  flipem();
  659.                                        /* Repair background */
  660.  BltBitMap(Bmap[2],ox[0],oy[0],Bmap[frame],ox[0],oy[0],13,15,0xC0,0xff,NULL); 
  661.  BltBitMap(Bmap[2],ox[1],oy[1],Bmap[frame],ox[1],oy[1],13,15,0xC0,0xff,NULL);
  662.  if (bflag[0]) BltBitMap(Bmap[2],obx[0],oby[0],Bmap[frame],
  663.                obx[0],oby[0],9,9,0xC0,0xff,NULL);
  664.  if (bflag[1]) BltBitMap(Bmap[2],obx[1],oby[1],Bmap[frame],
  665.                obx[1],oby[1],9,9,0xC0,0xff,NULL);
  666.  if (dead[0])
  667.      BltBitMap(Bmap[2],px[0]-2,py[0]-2,Bmap[frame],
  668.      px[0]-2,py[0]-2,19,17,0xC0,0xff,NULL);
  669.  if (dead[1])
  670.      BltBitMap(Bmap[2],px[1]-2,py[1]-2,Bmap[frame],
  671.      px[1]-2,py[1]-2,19,17,0xC0,0xff,NULL);
  672.  ox[0]=px[0],oy[0]=py[0],ox[1]=px[1],oy[1]=py[1];
  673.  obx[0]=bx[0],oby[0]=by[0],obx[1]=bx[1],oby[1]=by[1];
  674.  obstate[0]=bstate[0],obstate[1]=bstate[1];
  675. }
  676.  
  677. void flipem()                          /* Double-buffer controller */
  678. {
  679.   while (VBeamPos() != 250);
  680.   setbitmap();
  681.   frame = (1 - frame);
  682.   scr->BitMap = *Bmap[frame];
  683. }
  684.  
  685. void pause(pcount)
  686. USHORT pcount;
  687. {
  688.  short i;
  689.  for (i=0;i<pcount;i++) WaitBOVP(vp);   
  690. }
  691.     
  692. void cleantheamiga()                   /* cleanup routine */
  693. {
  694.  register short i,j;
  695.  Permit();
  696.  ClearPointer(wdw);
  697.  KillSounds();
  698.  if (wdw != NULL) CloseWindow(wdw);
  699.  if (scr != NULL) CloseScreen(scr);
  700.  for (j=0; j<5; j++)
  701.    { if (Bmap[j] != NULL)
  702.        { for (i=0; i<4; i++)
  703.          { if (Bmap[j]->Planes[i] != 0)
  704.            FreeRaster(Bmap[j]->Planes[i],320,200);
  705.          }
  706.         FreeMem(Bmap[j], sizeof(struct BitMap));
  707.        }
  708.    }
  709.  CloseLibrary(IntuitionBase);
  710.  CloseLibrary(GfxBase);
  711.  exit(FALSE);
  712. }
  713.